package com.well.register.data;

import com.well.rpc.model.ClusterServerModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 存放 注册中心集群节点信息。
 */
public class ClusterDataCenter {

    private static Integer status;

    private static AtomicBoolean isRegisterSelf = new AtomicBoolean(false);

    private static Logger logger = LoggerFactory.getLogger(ClusterDataCenter.class);

    private static ConcurrentHashMap<String, ClusterServerModel> clusters = new ConcurrentHashMap();

    public static void setClusterServerModel(ClusterServerModel model) {
        String key = model.getHost() + model.getPort();
        if (clusters.get(key) != null) {
            logger.info("此IP已注册！" + model.getHost() + ":" + model.getPort());
            return;
        }
        clusters.put(key, model);
    }

    public static AtomicBoolean getIsRegisterSelf() {
        return isRegisterSelf;
    }

    public static ConcurrentHashMap<String, ClusterServerModel> getClusters() {
        return clusters;
    }

    public static Integer getStatus() {
        return status;
    }

    public static void setStatus(Integer status) {
        ClusterDataCenter.status = status;
    }
}
